package main

import (
	"context"
	"fmt"
	"log"

	pb "code.tencent.com/Gomicro/protofiles"
	micro "github.com/micro/go-micro"
)

//  声明结构体
type Encrypter struct{}

func (g Encrypter) Encrypt(c context.Context, request *pb.Request, response *pb.Response) error {
	response.Result = request.Message + request.key
	return nil
}

func (g Encrypter) Decrypt(c context.Context, request *pb.Request, response *pb.Response) error {
	response.Result = request.Message + request.key
	return nil
}

func main() {
	// 得到服务端实例
	service := micro.NewService(
		// 设置微服务名称，用来访问
		micro.Name("encrypter"),
	)

	// 初始化
	service.Init()

	// 服务注册
	err := pb.RegisterEncrypterHandler(service.Server(), new(Encrypter))
	if err != nil {
		fmt.Println(err)
	}

	// 启动服务
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
